package com.jx.lcs.integral.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tianyu.jty.common.persistence.HibernateDao;
import com.tianyu.jty.common.service.BaseService;
import com.jx.lcs.integral.dao.IntegralTypeDao;
import com.jx.lcs.integral.entity.IntegralType;

/**
 * 积分类型service
 * @author ty
 * @date 2015年1月22日
 */
@Service
@Transactional(readOnly=true)
public class IntegralTypeService extends BaseService<IntegralType, String> {
	
	@Autowired
	private IntegralTypeDao integralTypeDao;

	@Override
	public HibernateDao<IntegralType, String> getEntityDao() {
		return integralTypeDao;
	}
	
	/**
	 * 根据类型编码获取积分类型
	 * @param name
	 * @return
	 */
	public IntegralType findIntegralTypeByTypeName(String name) {
		List<IntegralType> list = integralTypeDao.findBy("name", name);
		IntegralType integralType = null;
		if(list != null && list.size() > 0) {
			integralType = list.get(0);
		}
		return integralType;
	}
	
	/**
	 * 判断该用户是否已有代理该产品的积分
	 * @param uid
	 * @param pcode
	 * @return
	 */
	public int isHaveAgentIntegral(String uid, String pcode){
		return integralTypeDao.isHaveAgentIntegral(uid, pcode);
	}

}
